import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 佳宝首页相关接口
 *
 * allen  2023-12-19
 */

/**
 * 
 * 查询首页配置
 */
const queryHomeFrontConfig = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/index").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 
 * 查询全局配置
 */
const querGlobalConfig = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/index/global/config").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 热门/推荐 搜索关键词
 */
const queryRecommendSearchWords = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/search/keyword").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 搜索产品
 */
const querySearchProducts = (searchWord, page = 1, limit = 10, isPartner = "", isPersonCustom = "", tag = "") => {
  return new Promise((resolve, reject) => {
    let data = {
      keyword: searchWord,
      page: page,
      limit: limit,
      isPartner: isPartner,
      isPersonCustom: isPersonCustom,
      tag,
    }
    get("/api/front/products", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
const queryNewSearchProducts = (searchWord, page = 1, limit = 10, isPartner = "", isPersonCustom = "", tag = "") => {
  return new Promise((resolve, reject) => {
    let data = {
      keyword: searchWord,
      page: page,
      limit: 10,
      isPartner: isPartner,
      isPersonCustom: isPersonCustom,
      tag,
    }
    get("/api/front/products", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 搜索小店产品
 */
const querySearchShopProducts = (searchWord, page = 1, limit = 10) => {
  return new Promise((resolve, reject) => {
    get("/api/front/little/shop/products?keyword=" + searchWord + "&page=" + page + "&limit=" + limit).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 最底部的商品分类
 */
const queryCategoryProducts = (type, page, limit = 10) => {
  return new Promise((resolve, reject) => {
    let url = "/api/front/index/product/" + type + "?page=" + page + "&limit=" + limit
    get(url).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 热门推荐产品列表
 */
const queryHotRecommendProducts = (page = 1, limit = 6) => {
  return new Promise((resolve, reject) => {
    get("/api/front/product/hot?page=" + page + "&limit=" + limit).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}


/**
 * 创建预约揭露
 */
const createAppointRecord = (data) => {
  return new Promise((resolve, reject) => {
    post('/api/front/visit/store/create', data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 查询门店列表
 */
const queryShopList = () => {
  return new Promise((resolve, reject) => {
    get('/api/front/visit/store/store').then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
 * 门店预约列表
 */
const queryVisitStoreList = () => {
  return new Promise((resolve, reject) => {
    get('/api/front/oa/visit/store/list?page=1&limit=300').then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 我的门店预约列表
 */
const queryMyVisitStoreList = (introUserId) => {
  return new Promise((resolve, reject) => {
    get('/api/front/visit/store/list?page=1&limit=300&introUserId=' + introUserId).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 更新处理状态
 */
const updateDealStatus = (data) => {
  return new Promise((resolve, reject) => {
    put('/api/front/oa/visit/store/deal', data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}




module.exports = {
  queryHomeFrontConfig,
  queryRecommendSearchWords,
  querySearchProducts,
  queryCategoryProducts,
  queryHotRecommendProducts,
  querySearchShopProducts,
  queryNewSearchProducts,
  querGlobalConfig,

  createAppointRecord,
  queryShopList,
  queryVisitStoreList,
  updateDealStatus,
  queryMyVisitStoreList,

}
